package com.imooc.controller;


import com.imooc.pojo.Orders;
import com.imooc.service.MyOrdersService;
import com.imooc.utils.IMOOCJSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.io.File;

/**
 * @author: ZhaoYiChen
 * @create: 2020-09-10 09:45
 **/
@Controller
public class BaseController {
    public static final String FOODIE_SHOPCART = "shopcart";
    public static final Integer COMMON_PAGE_SIZE = 10;
    public static final Integer PAGE_SIZE = 20;

    // 支付中心的调用地址
    String paymentUrl = "http://payment.t.mukewang.com/foodie-payment/payment/createMerchantOrder";

    //微信支付成功->支付中心->天天吃货平台
    //                      -> 回调通知url
    // natapp.exe 工具 洞穿内网 每次启动工具 http://8nuk8s.natappfree.cc 会发生变化
   // String payReturnUrl = "http://8nuk8s.natappfree.cc/orders/notifyMerchantOrderPaid";
    String payReturnUrl = "http://192.168.64.38:8088/foodie-dev-api/orders/notifyMerchantOrderPaid";


    // 用户上传头像位置
    public static final String IMAGE_USER_FACE_LOCATION = File.separator + "workspaces" +
            File.separator + "images" +
            File.separator + "foodie" +
            File.separator + "faces";

    @Autowired
    public MyOrdersService myOrdersService;

    /**
     * 用于验证用户和订单是否有关联关系，避免非法用户调用
     *
     * @return
     */
    public IMOOCJSONResult checkUserOrder(String userId, String orderId) {
        Orders order = myOrdersService.queryMyOrder(userId, orderId);
        if (order == null) {
            return IMOOCJSONResult.errorMsg("订单不存在！");
        }
        return IMOOCJSONResult.ok(order);
    }
}